package com.vita.core.device.convert;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

import com.vita.common.PojoUtils;
import com.vita.core.function.Func2;

public class PojoConvert implements Func2 {
    private Class<?> clazz;
    
    @Override
    public Object apply(Object t) {
        List<String> list = (List<String>) t;
        List<Object> listClass = new ArrayList<>();
        for(String s:list){
            String[] str = s.split(",");
            try {
                Object pojo = PojoUtils.getObjectList(clazz, str);
                listClass.add(pojo);
            } catch (Exception e) {
                e.printStackTrace();
            }
            
        }
        return listClass;
    }

    @Override
    public void borrow(Queue<Object> bank) {
        if(this.clazz == null){
            this.clazz = (Class)bank.poll();
        }
    }
    
}
